package com.embhealth.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.embhealth.dao.SportDao;
import com.embhealth.entity.PageResult;
import com.embhealth.entity.QueryPageBean;
import com.embhealth.pojo.Food;
import com.embhealth.pojo.Sport;
import com.embhealth.service.SportService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program: chuanzhi_helath
 * @description: 运动管理
 * @author: xu jiangdong
 * @DateTime: 2020-08-21 15:58
 **/
@Service(interfaceClass = SportService.class)
@Transactional
public class SportServiceImpl implements SportService {

    @Autowired
    private SportDao sportDao;

    /**
     * 上传运动管理数据
     *
     * @param sports
     */
    @Override
    public void handleAdd(List<Sport> sports) {
        for (Sport sport : sports) {
            sportDao.handleAdd(sport);
        }
    }

    /**
     * 分页查询
     *
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        String queryString = queryPageBean.getQueryString();
        //完成分页查询基于mybatis框架的PageHelper分页助手
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        Page<Sport> page = sportDao.findPage(queryString);
        return new PageResult(page.getTotal(), page.getResult());
    }

    /**
     * 添加单项数据
     * @param sport
     */
    @Override
    public void handleAdd(Sport sport) {
        sportDao.handleAdd(sport);
    }
}
